# -*- coding: UTF-8 -*-
import tkinter as tk
from tkinter import filedialog 
import tkinter.messagebox
from fntCopyer import textureCopyer
def main():
    window = tk.Tk()
    screenwidth = window.winfo_screenwidth()
    screenheight = window.winfo_screenheight()
    width = 600
    height = 120
    size = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
  
    window.title('字体打包')
    window.geometry(size)
    window.resizable(width = False, height = False)

    labText = tk.StringVar() 
    lab1 = tk.Label(window, textvariable = labText , font=('Arial', 14), bg = '#dddddd', width = 40, anchor = 'w')
    lab1.place(x = 150, y = 10)

    lab3 = tk.Label(window, text="输出", font=('Arial', 14))
    lab3.place(x = 20, y = 50)

    labText1 = tk.StringVar()    
    input1 = tk.Entry(window, font=('Arial', 14),textvariable = labText1, bg = '#dddddd', width = '40')
    input1.place(x=150, y=50)

    def openBtnClick():
        filename = filedialog.askdirectory()
        labText.set(filename)
        outName = filename[(filename.rfind("/") + 1):]
        dirName = filename[0:filename.rfind("/")+ 1]
        labText1.set(dirName+"output/"+outName)
    def packerBtnClick():
        inputName = labText.get()
        outName = input1.get()
        if outName == "":
            outName = inputName[(inputName.rfind("/") + 1):]
            dirName = inputName[0:inputName.rfind("/")+ 1]
            outName = dirName+"output/"+outName
        if textureCopyer(inputName, outName):
            tk.messagebox.askokcancel(title = '提示',message='打包成功')
        else:
            tk.messagebox.askokcancel(title = '提示',message='打包失败')
    openBtn = tk.Button(window, text='打开', font=('Arial', 12), width=10, height=1, command=openBtnClick)
    openBtn.place(x = 20, y = 10)

    packerBtn = tk.Button(window, text='打包', font=('Arial', 12), width=10, height=1, command=packerBtnClick)
    packerBtn.place(x = 250, y = 80)

    window.mainloop()


if __name__ == '__main__':
    main()
